package com.ruoyi.project.system.history.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.history.domain.MemberGoodsHistory;
import com.ruoyi.project.system.history.service.IMemberGoodsHistoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户足迹Controller
 * 
 * @author LCL
 * @date 2020-12-17
 */
@Controller
@RequestMapping("/system/history")
public class MemberGoodsHistoryController extends BaseController
{
    private String prefix = "system/history";

    @Autowired
    private IMemberGoodsHistoryService memberGoodsHistoryService;

    @RequiresPermissions("system:history:view")
    @GetMapping()
    public String history()
    {
        return prefix + "/history";
    }

    /**
     * 查询用户足迹列表
     */
    @RequiresPermissions("system:history:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberGoodsHistory memberGoodsHistory)
    {
        startPage();
        List<MemberGoodsHistory> list = memberGoodsHistoryService.selectMemberGoodsHistoryList(memberGoodsHistory);
        return getDataTable(list);
    }

    /**
     * 导出用户足迹列表
     */
    @RequiresPermissions("system:history:export")
    @Log(title = "用户足迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberGoodsHistory memberGoodsHistory)
    {
        List<MemberGoodsHistory> list = memberGoodsHistoryService.selectMemberGoodsHistoryList(memberGoodsHistory);
        ExcelUtil<MemberGoodsHistory> util = new ExcelUtil<MemberGoodsHistory>(MemberGoodsHistory.class);
        return util.exportExcel(list, "history");
    }

    /**
     * 新增用户足迹
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户足迹
     */
    @RequiresPermissions("system:history:add")
    @Log(title = "用户足迹", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberGoodsHistory memberGoodsHistory)
    {
        return toAjax(memberGoodsHistoryService.insertMemberGoodsHistory(memberGoodsHistory));
    }

    /**
     * 修改用户足迹
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MemberGoodsHistory memberGoodsHistory = memberGoodsHistoryService.selectMemberGoodsHistoryById(id);
        mmap.put("memberGoodsHistory", memberGoodsHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户足迹
     */
    @RequiresPermissions("system:history:edit")
    @Log(title = "用户足迹", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberGoodsHistory memberGoodsHistory)
    {
        return toAjax(memberGoodsHistoryService.updateMemberGoodsHistory(memberGoodsHistory));
    }

    /**
     * 删除用户足迹
     */
    @RequiresPermissions("system:history:remove")
    @Log(title = "用户足迹", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberGoodsHistoryService.deleteMemberGoodsHistoryByIds(ids));
    }
}
